<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>ver管理</title>
	<link rel="stylesheet" href="/css/common2.css">
<link rel="stylesheet" href="/scriptZIP/layui.min.css">
	<style>
		.a {
			max-width: 200px;
			white-space: pre-wrap;
		}
	</style>

</head>

<body class="main-body">

	<div id="vue-root" style="margin-top: 50px;">
		<div class="add action-buttons">
			<a :href="'apk_ver_item.html?id='+apk.id" style="color: white">添加版本</a>
		</div>
		<div class="table ">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box">序号
						</th>
						<th>版本</th>
						<th>versionCode</th>
						<th>上传时间</th>
						<th>描述</th>
						<th>状态</th>
						<th>编辑/删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(ver,index) in apk.versions" :key="index">
						<td>
							<input type="checkbox" class="check-box" v-model="ver.checked">
							<span v-text="index+1"></span>
						</td>
						<td v-text="ver.name"></td>
						<td v-text="ver.code"></td>
						<td v-text="ver.time"></td>
						<td v-text="ver.remark" class="a"></td>
						<td v-text="ver.disabled?'暂停':'启用'"></td>
						<td>
							<a :href="'/static/0/apk/'+ver.file">下载</a>
							<button @click="toggle(ver)" v-text="ver.disabled?'启用':'暂停'"></button>
							<button @click="del(index)">删除</button>
						</td>
					</tr>
				</tbody>
			</table>
		</div>

	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>
	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>

	<script>

		var app = new Vue({
			el: '#vue-root',
			data: {
				apk: {
					versions: []
				}
			},
			created: function () {
				this.getData();
			},
			methods: {
				getData: function () {
					axios.get('/pc/apk/' + params().id).then(function (res) {
						this.apk = res.data;
					}.bind(this));
				},
				update: function () {
					axios.put('/pc/apk', this.apk).then(function (res) {
						this.getData();
					}.bind(this));
				},
				del: function (index) {
					if (!confirm('确认')) return;
					this.apk.versions.splice(index, 1);
					this.update();
				},
				toggle: function (ver) {
					ver.disabled = !ver.disabled;
					this.update();
				}
			}
		});
	</script>
</body>

</html>